<template>
  <page-header-wrapper>
    <a-card :bordered="false" class="search">
      <div class="searchBox">
        <a-input placeholder="请输入昵称" v-model="queryParam.name">
          <a-icon slot="suffix" type="search" />
        </a-input>
        <div class="select">
          <span>等级：</span>
          <a-select style="width: 220px" v-model="queryParam.level_id">
            <a-select-option :value="item.id" v-for="item in levelList" :key="item.id">
              {{ item.name }}
            </a-select-option>
          </a-select>
        </div>
        <a-button type="primary" @click="getList">查询</a-button>
      </div>
    </a-card>
    <a-card :bordered="false" class="card_style_re" style="margin-top: 20px">
      <a-page-header :breadcrumb="{ props: { routes } }" />
      <a-table
        :rowKey="
          (r, i) => {
            return i
          }
        "
        :pagination="{
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange,
        }"
        :columns="columns"
        :data-source="list"
        :scroll="{ x: 'max-content' }"
      >
        <div slot="name" slot-scope="text, record">
          <div class="name">
            <div class="pic">
              <img :src="record.avatar || record.avatar_url" alt="" />
            </div>
            <div class="info">
              <span>{{ record.name || record.nickname }}</span>
            </div>
          </div>
        </div>
        <span slot="mobile" slot-scope="scope"> {{ scope.name }} / {{ scope.mobile }} </span>
        <span slot="audit_time" slot-scope="text">
          {{ text > 0 ? $moment(text * 1000).format('YYYY-MM-DD HH:mm:ss') : '-' }}
        </span>
        <span slot="level_name" slot-scope="text">
          {{text? text:'-'}}
        </span>
        <span slot="range_profit" slot-scope="text"> ￥{{ text || 0 }} </span>
        <span slot="holder_profit" slot-scope="text"> ￥{{ text || 0 }} </span>
        <div slot="action" slot-scope="scope">
          <div class="action">
            <a-button type="link" @click="jonior(scope)" size="small">查看下级</a-button>
          </div>
        </div>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { allLevel, junior } from '@/api/shareholder'
const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '会员信息',
    scopedSlots: {
      customRender: 'name',
    },
    width: 200,
  },
  {
    title: '会员等级',
    dataIndex: 'level_name',
    scopedSlots: {
      customRender: 'level_name',
    },
  },
  {
    title: '一级下级人数',
    dataIndex: 'level_one_count',
  },
  {
    title: '团队人数',
    dataIndex: 'level_count',
  },
  {
    title: '极差佣金',
    dataIndex: 'range_profit',
    scopedSlots: {
      customRender: 'range_profit',
    },
  },
  {
    title: '股东分红佣金',
    dataIndex: 'holder_profit',
    scopedSlots: {
      customRender: 'holder_profit',
    },
  },
  {
    title: '操作',
    scopedSlots: {
      customRender: 'action',
    },
  }
]
export default {
  data() {
    return {
      // 搜索参数
      queryParam: {
        user_id:0,
        name: null,
        level_id: null,
        pageNo: 1,
        pageSize: 10,
      },
      // 请求的数据列表
      list: [],
      // 表格列配置
      columns,
      // 数据条数
      totalCount: 0,
      // 所有等级列表
      levelList: [],
      routes: [
        {
          path: 'plugins/shareholder/index?tab=1',
          breadcrumbName: '股东列表',
        },
        {
          path: 'plugins/shareholder/join',
          breadcrumbName: '一级团队人数',
        },
      ],
    }
  },
  methods: {
    // 获取数据列表
    async getList() {
      const hide = this.$message.loading('加载中', 0)
      const res = await junior(this.queryParam)
      if (res.code == 0) {
        this.totalCount = res.data.totalCount
        this.list = res.data.data
      }
      hide()
    },
    // 分页请求
    tablePageChange(e) {
      this.queryParam.pageNo = e
      this.getList()
    },
    // 获取所有等级列表
    async allLevel() {
      const res = await allLevel()
      if (res.code == 0) {
        this.levelList = res.data
      }
    },
    // 点击查看下级人数
    jonior(e) {
      console.log(e);
      this.queryParam.user_id = e.id
      this.queryParam.pageNo = 1
      this.getList()
    }
  },
  mounted() {
    this.queryParam.user_id = this.$route.query.id
    this.allLevel()
    this.getList()
  },
}
</script>

<style lang="less" scoped>
.search {
  /deep/ .ant-card-body {
    padding-top: 0 !important;
    padding-bottom: 14px !important;
  }
}
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-top: 14px;
    margin-right: 20px;
  }
  .select {
    display: flex;
    align-items: center;
    margin-top: 14px;
    margin-right: 20px;
  }
  .ant-btn {
    margin-top: 14px;
  }
}
.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
.action {
  display: flex;
  align-items: center;
  .line {
    width: 1px;
    height: 14px;
    background-color: #d8d8d8;
  }
}
.level_one_count {
  text-decoration: underline;
  cursor: pointer;
  color: #ff4400;
}
</style>